package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.ydd.common.BusinessException;
import com.itheima.ydd.entity.YddAdvimg;
import com.itheima.ydd.entity.YddAdvpos;
import com.itheima.ydd.mapper.YddAdvposMapper;
import com.itheima.ydd.service.IYddAdvimgService;
import com.itheima.ydd.service.IYddAdvposService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@Service
public class YddAdvposServiceImpl extends ServiceImpl<YddAdvposMapper, YddAdvpos> implements IYddAdvposService {
    @Autowired
    private IYddAdvimgService iYddAdvimgService;

    /**
     * 根据id删除之前进行判断
     * @param id
     */
    @Override
    public void removeByIdss(int id) {
        //条件构造器
        LambdaQueryWrapper<YddAdvimg> queryWrapper = new LambdaQueryWrapper<>();
        //根据id进行查询
        queryWrapper.eq(YddAdvimg::getAdvimgpos,id);
        int count = iYddAdvimgService.count(queryWrapper);
        //如果已经关联
        if(count > 0){
            throw new BusinessException("当前关联了广告图，不能删除");
        }

        super.removeById(id);
    }
}
